package java_DesignPattern.BehavioralPattern.StatePattern.Before;

/**
 * 电梯类
 */
public class Lift implements ILift {

    private int state;

    @Override
    public void setState(int state) {
        this.state = state;
    }

    @Override
    public void run() {
        switch (state){
            case STOPPING:
                System.out.println("电梯运行,不能停止");
                break;
            case RUNNING:
                break;
            case OPENING:
                System.out.println("电梯运行,不能开门");
                break;
            case CLOSED:
                System.out.println("电梯运行,不能关门");
                break;
        }
    }

    @Override
    public void stop() {
        switch (state){
            case RUNNING:
                System.out.println("电梯停止");
                break;
            case STOPPING:
                break;
            case OPENING:
                System.out.println("电梯停止,不能关门");
                break;
            case CLOSED:
                System.out.println("电梯停止,不能开门");
                break;
        }
    }

    @Override
    public void open() {
        switch (state){
            case RUNNING:
                System.out.println("电梯开门,不能运行");
                break;
            case STOPPING:
                System.out.println("电梯开门,不能停止");
                break;
            case OPENING:
                break;
            case CLOSED:
                System.out.println("电梯开门,不能关门");
                break;
        }
    }

    @Override
    public void close() {
        switch (state){
            case RUNNING:
                System.out.println("电梯关门,不能运行");
                break;
            case STOPPING:
                System.out.println("电梯关门,不能停止");
                break;
            case OPENING:
                System.out.println("电梯关门,不能开门");
                break;
            case CLOSED:
                break;
        }
    }
}
